package org.linlinjava.litemall.db.service;

import org.linlinjava.litemall.db.dao.LitemallOrderGoodsMapper;
import org.linlinjava.litemall.db.domain.LitemallOrderGoods;
import org.linlinjava.litemall.db.domain.LitemallOrderGoodsExample;
import org.linlinjava.litemall.db.domain.LitemallOrderGoodsExcel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class LitemallOrderGoodsService {
    @Resource
    private LitemallOrderGoodsMapper orderGoodsMapper;


    public int add(LitemallOrderGoods orderGoods) {
        return orderGoodsMapper.insertSelective(orderGoods);
    }

    public List<LitemallOrderGoods> queryByOid(Integer orderId) {
        LitemallOrderGoodsExample example = new LitemallOrderGoodsExample();
        example.or().andOrderIdEqualTo(orderId).andDeletedEqualTo(false);
        return orderGoodsMapper.selectByExample(example);
    }

    public List<LitemallOrderGoods> queryByOids(Integer orderId) {
        LitemallOrderGoodsExample example = new LitemallOrderGoodsExample();
        example.or().andOrderIdEqualTo(orderId).andDeletedEqualTo(false);
        LitemallOrderGoods.Column[] columns = new LitemallOrderGoods.Column[]{ LitemallOrderGoods.Column.number,LitemallOrderGoods.Column.goodsName, LitemallOrderGoods.Column.goodsId, LitemallOrderGoods.Column.price, LitemallOrderGoods.Column.integral, LitemallOrderGoods.Column.priceFlag, LitemallOrderGoods.Column.integralFlag,LitemallOrderGoods.Column.remark};
        return orderGoodsMapper.selectByExampleSelective(example ,columns);
    }

    public List<LitemallOrderGoodsExcel> queryInfo(Integer orderId){
        return orderGoodsMapper.queryInfo(orderId);
    }

    public List<LitemallOrderGoods> findByOidAndGid(Integer orderId, Integer goodsId) {
        LitemallOrderGoodsExample example = new LitemallOrderGoodsExample();
        example.or().andOrderIdEqualTo(orderId).andGoodsIdEqualTo(goodsId).andDeletedEqualTo(false);
        return orderGoodsMapper.selectByExample(example);
    }
    public List<LitemallOrderGoods> queryByOidAndGoodId(Integer orderId, Integer goodsId) {
        LitemallOrderGoodsExample example = new LitemallOrderGoodsExample();
        example.or().andOrderIdEqualTo(orderId).andDeletedEqualTo(false).andGoodsIdEqualTo(goodsId);
        return orderGoodsMapper.selectByExample(example);
    }

    public List<LitemallOrderGoods> queryByGoodId(Integer goodsId) {
        LitemallOrderGoodsExample example = new LitemallOrderGoodsExample();
        example.or().andDeletedEqualTo(false).andGoodsIdEqualTo(goodsId);
        return orderGoodsMapper.selectByExample(example);
    }

    public int updateOrderGoodsById(LitemallOrderGoods orderGoods) {
        return orderGoodsMapper.updateByPrimaryKey(orderGoods);
    }

    public int  updateOrderGoods(LitemallOrderGoods orderGoods) {
        return orderGoodsMapper.updateByPrimaryKeySelective(orderGoods);
    }
}
